/*
 * @Author: czy
 * @Date: 2021-05-21 13:00:03
 * @LastEditTime: 2021-05-21 22:04:43
 */
#include "datetime.h"

#include "api/system.h"

static tm now;

/**
 * @description: Returns the current timestamp.
 * @return Timestamp.
 */
time_t time(void)
{
    return gettime();
}

/**
 * @description: Returns the current time structure.
 * @return Time structure.
 */
tm gmtime(void)
{
    time_t locale_t = gettime();
    localtime(&locale_t, &now);
    return now;
}

/**
 * @description: Make the currently executing thread pause for secs seconds before continuing.
 * @param secs  Time to sleep.
 */
void sleep(unsigned secs)
{
    time_t start = time();
    while (time() - start < secs)
        ;
}
